"""
TODO: 到底用 form 传数据还是用 json 传数据，取决于接口文档。
TODO: data={},    json={},  你可以手工修改 content-type
"""
import requests

# 发送请求：1、url, 2, 请求方法

url = 'http://httpbin.org/post'
# 发送 form data 形式的请求数据
# query_string = {"username": "yuze"}
# headers = {"xxx": "yyy", "age": "18", "token": "fowoepfwfe"}
# body = {"a": "b"}
# response = requests.post(url, params=query_string, headers=headers, data=body)
#
# print(response.text)


# 发送 json 数据格式
# query_string = {"username": "yuze"}
# headers = {"xxx": "yyy", "age": "18", "token": "fowoepfwfe"}
# body = {"a": "b"}
# response = requests.post(url, params=query_string, headers=headers, json=body)
#
# print(response.text)


# 发送 JSON 数据也可以通过 data 关键字参数
query_string = {"username": "yuze"}
headers = {"xxx": "yyy", "age": "18", "token": "fowoepfwfe",
           "content-type": "application/json"}
body = {"a": "b"}
response = requests.post(url, params=query_string, headers=headers, json=body)

print(response.text)



